package com.demo.order.elasticjob.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.annotation.ElasticJobConfiguration;
import org.apache.shardingsphere.elasticjob.annotation.ElasticJobProp;
import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;

import java.util.Map;

@Slf4j
public class LocalListener implements ElasticJobListener {
    public LocalListener(){}
    @Override
    public void beforeJobExecuted(ShardingContexts shardingContexts) {
        int shardingTotalCount = shardingContexts.getShardingTotalCount();
        String jobParameter = shardingContexts.getJobParameter();
        String jobName = shardingContexts.getJobName();
        Map<Integer,String> shardingParameter = shardingContexts.getShardingItemParameters();
        int jobEventSamplingCount = shardingContexts.getJobEventSamplingCount();
        int currentJobEventSamplingCount = shardingContexts.getCurrentJobEventSamplingCount();

        log.info("shardingTotalCount={}, jobParameter={}, jobName={}, shardingParameter={}, jobEventSamplingCount={}, currentJobEventSamplingCount={}",
                shardingTotalCount,jobParameter,jobName,shardingParameter.toString(),jobEventSamplingCount,currentJobEventSamplingCount);
    }

    @Override
    public void afterJobExecuted(ShardingContexts shardingContexts) {
        log.info("执行完毕");
    }

    @Override
    public String getType() {
        return "localListener";
    }
}
